﻿<%@ WebHandler Language="C#" Class="AutoComplete" %>

using System;
using System.Web;
using MySql.Data.MySqlClient;
using System.Configuration;

public class AutoComplete : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        using (MySqlConnection connection = new MySqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["patrimonio"].ConnectionString))
        using (MySqlCommand command = new MySqlCommand("SELECT NomeEstacao FROM estacao WHERE (NomeEstacao LIKE '" + context.Request.QueryString["q"] + "%')", connection))
        {
            connection.Open();

            using (MySqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    context.Response.Write(reader[0].ToString() + Environment.NewLine);
                }
            }
        }
    }


    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
